<template>
  <div class="batchAppraisal">
    <el-form :model="ruleForm"
             ref="ruleForm"
             label-width="130px"
             class="yuyi-ruleForm">
      <el-form-item label="鉴定结果" prop="name">
        <el-select size="small" v-model="ruleForm.mdCode" placeholder="请选择类型">
          <el-option v-for="(item, index) in selectData"
                     :key="index"
                     :label="item.dictLabel"
                     :value="item.dictValue"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="鉴定理由" prop="name" v-if="showNewVal.includes(ruleForm.mdCode)">
        <el-input type="textarea"
                  size="small"
                  show-word-limit
                  maxlength="200"
                  :autosize="autosize"
                  v-model="ruleForm.newVal"></el-input>
      </el-form-item>

      <el-form-item label="">
        <el-button size="small" :loading="subLoading" type="primary" @click="submitForm('ruleForm')">提交</el-button>
        <el-button size="small" :loading="subLoading" @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>

    </el-form>
  </div>
</template>

<script>
import { requestOpenBatch } from '../../../../../api/appraisal'
import { getArchivesDicId } from '../../../../../api/dictionary/dictionary'

export default {
  name: 'batchOpenAppraisal',
  props: {
    changesData: {
      type: Array,
      default: () => ([])
    },
    idCategory: {
      default: ''
    }
  },
  data () {
    return {
      autosize: {
        minRows: 6,
        maxRows: 8
      },
      ruleForm: {
        mdCode: '',
        newVal: ''
      },
      selectData: [],
      showNewVal: ['A', 'B', 'E'],
      subLoading: false
    }
  },
  mounted () {
    this.getDic()
  },
  methods: {
    getDic () {
      getArchivesDicId('kzbs').then(res => {
        this.selectData = res.data.data
      })
    },
    submitForm (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.subLoading = true
          this.ruleForm.ids = []
          this.changesData.map(item => {
            this.ruleForm.ids.push(item.id)
          })
          requestOpenBatch(this.ruleForm, { idCategory: this.idCategory }).then(res => {
            // console.log(res.data)
            this.$message.success('操作成功！')
            this.$emit('handleSuccess')
            this.subLoading = false
          }).catch(() => {
            this.subLoading = false
          })
        } else {
          return false
        }
      })
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style lang="scss" scoped>
  .batchAppraisal {
    height: 100%;

    .yuyi-ruleForm {
      padding-right: 80px;

      ::v-deep .el-select {
        width: 100%;
      }
    }
  }
</style>
